package controllers.classes;

import hprose.HproseClinetService;

import java.util.HashMap;
import java.util.Map;

import play.Logger;
import play.cache.Cache;
import utils.convert.Convert;
import utils.logs.LogsUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import component.UserBis;
import constants.APIConstants;
import constants.Constants;
import controllers.common.filter.BaseFilter;

public class ClassesManageAction extends BaseFilter {
	/**
	 * 班别主页 
	 * 
	 * 2015年12月31日 上午10:57:23
	 * @auth huan208050@vip.qq.com
	 */
	public static void index(){
		render();
	}
	/**
	 * 获取所有班组
	 * 
	 * 2015年12月31日 上午11:58:45
	 * @auth huan208050@vip.qq.com
	 */
	public static void getAllClasses(){
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("customer_id", UserBis.currUser());
		Object[] arguments = new Object[]{map};
		String classes = HproseClinetService.synCall(APIConstants.CMI_GETCLASSESLIST, arguments,APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
		JSONObject json = JSONObject.parseObject(classes);
		renderJSON(json.get("data"));
	}
	
	public static void addClasses(){
		String data = params.get("data");
		Logger.info(data);
		String customer_id = UserBis.currUser()+"";
		JSONArray ja = JSONArray.parseArray(data);
//		for(int i=0;i<ja.size();i++){
//			JSONObject json = (JSONObject)ja.get(i);
//			String class_name = json.getString("class_name");
//			String startTime=json.getString("startTime");
//			String endTime=json.getString("endTime");
//			String class_id=json.getString("class_id");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("customer_id", customer_id);
//			map.put("class_name", class_name);
//			map.put("startTime", startTime);
//			map.put("endTime", endTime);
		map.put("data", data);
		Object[] arguments = new Object[]{map};
		LogsUtils.addLogs(Constants.LOG_TYPE_UPDATE,Convert.convertToInt(UserBis.currOperatorId(),-1), 1, "执行班别修改","success", UserBis.currLoginAccount(), UserBis.currUserName(), UserBis.currUser());
		String ret = HproseClinetService.synCall(APIConstants.CMI_ADDCLASSESLIST, arguments, APIConstants.CUSTOMER_HOST, APIConstants.CUSTOMER_PORT);
		Logger.info("ret->"+ret);
//		}
		
	}
}
